﻿using Castle.Windsor;
using Castle.Windsor.Installer;
using MvcTests.BestPractice.ApplicationService.ContainerInstallers;
using MvcTests.BestPractice.IntegrationTests.WindsorContainer;
using MvcTests.BestPractice.Repository.ContainerInstallers;

namespace MvcTests.BestPractice.IntegrationTests
{
    public class TestingBootstrap
    {
        private static IWindsorContainer _container;

        public static IWindsorContainer CreateContainer()
        {
            if (_container == null)
            {
                _container=new Castle.Windsor.WindsorContainer();
                _container.ChangeComponentsLifestyleToScoped();

                _container.Install(FromAssembly.This());
                _container.Install(FromAssembly.Containing<ApplicationServiceInstaller>());
                _container.Install(FromAssembly.Containing<DbContextInstaller>());
            }

            return _container;
        }
    }
}